import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase = "DBshop005_订单管理查询订单流程"
# 1.新建一条余额支付的订单，并记录该订单号
firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)
firefox.find_element_by_xpath('//input[@name="keywords"]').send_keys('小米')
firefox.find_element_by_xpath('//input[@type="submit"]').click()
firefox.find_element_by_xpath('//a[@href="/dbshop/goods/8/2"]').click()
switchWindow(firefox,2)
firefox.find_element_by_id('add_cart_submit').click()
time.sleep(2)
firefox.find_element_by_link_text('去购物车结算').click()
firefox.find_element_by_link_text('去结算').click()
firefox.find_element_by_xpath('//input[@value="下一步"]').click()
firefox.find_element_by_xpath('//input[@value="yezf"]').click()
firefox.find_element_by_xpath('//input[@value="确认订单"]').click()
orderNO=firefox.find_element_by_xpath('(//font[@color="color:#ED145B"])[2]').text
rootPath=get_pro_rootpath()
writeFile(rootPath+'\public\order1.txt',orderNO)
firefox.find_element_by_xpath('//input[@value="马上去支付"]').click()
# 2.登录后台管理系统,地址是"http://localhost/dbshop/admin",
firefox.get(urlAdmin)
DBshopLoginAdmin(firefox)
# 3.进入销售管理订单管理,搜索该订单，查询订单信息
DBshopEnterMenu2(firefox,'销售管理','订单管理')
firefox.find_element_by_name('order_sn').send_keys(orderNO)
firefox.find_element_by_xpath('//button').click()
firefox.find_element_by_link_text('编辑查看').click()
# 断言
try:
    firefox.find_element_by_link_text("基本信息")
    writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()